<template>
  <a-modal
    :width='1400'
    :visible='visible'
    :confirm-loading='loading'
    :title="isUpdate ? '修改' : '新建'"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible='updateVisible'
    @ok='save'
  >
  <div class="ele-body ele-body-card">
    <!-- 顶部卡片 -->
    <a-card
      :bordered="true"
      :body-style="{padding: '20px'}">
      <a-form
        ref="form"
        :model="paramForm"
        :rules="rules"
        :label-col="{ md: { span: 11 }, sm: { span: 24 } }"
        :wrapper-col="{ md: { span: 13 }, sm: { span: 24 } }"
      >
        <a-row :gutter="8">
          <a-col :md="10" :sm="24" :xs="24">
            <a-form-item label='模板名称:' name='templateName'>
              <a-input v-model:value='form.templateName' allow-clear style="width: 300px;" />
            </a-form-item>
          </a-col>
          <a-col :md="1" :sm="24" :xs="24" />
          <a-col :md="4" :sm="24" :xs="24" >
            <a-form-item v-if="!isUpdate">
              <a-button type='primary' html-type='button' @click='syncSetting'>
                一键同步已有设备的配置
              </a-button>
            </a-form-item>
          </a-col>
          <a-col :md="9" :sm="24" :xs="24" />
        </a-row>
        <a-divider>总开关</a-divider>
        <a-row :gutter='8'>
          <a-col :md='12' :sm='24' :xs='24'>
            <a-form-item label='总开关' name='masterSwitch'>
              <a-switch
                checked-children='开'
                un-checked-children='关'
                autoFocus='false'
                :checked='paramForm.switch.masterSwitchCheck'
                @change='masterSwitchChange'
              />
            </a-form-item>
          </a-col>

          <a-col :md='12' :sm='24' :xs='24' />
        </a-row>
        <a-divider>转向相关参数</a-divider>
        <a-row :gutter='8'>
          <a-col :md='12' :sm='24' :xs='24'>
            <a-form-item label='转向判断依据' name='sourceSwitch'>
              <a-radio-group v-model:value='form.sourceSwitch'>
                <a-radio :value='1'>
                  仅靠堵转电流
                </a-radio>
                <a-radio :value='2'>
                  堵转电流或行程开关
                </a-radio>
              </a-radio-group>
            </a-form-item>
            <a-form-item label='电机反转的待机间隔时间(秒):' name='standbyTime'>
              <a-input style="width: 70%" v-model:value='form.standbyTime' placeholder='单位秒,范围从3到600秒' allow-clear />
            </a-form-item>
            <a-form-item label='电机反转的相电流门限(安培):' name='sourceCurrent'>
              <a-input style="width: 70%" v-model:value='form.sourceCurrent' placeholder='精确到小数点后2位' allow-clear />
            </a-form-item>
            <a-form-item label='清粪一次的大致时间(秒):' name='durationCleanOnce'>
              <a-input style="width: 70%" v-model:value='form.durationCleanOnce' placeholder='单位秒' allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24' :xs='24' />
        </a-row>

        <a-divider>防冻参数</a-divider>
        <a-row :gutter='8'>
          <a-col :md='12' :sm='24' :xs='24'>
            <a-form-item label='防冻模式' name='antifreezeMode'>
              <a-radio-group v-model:value='form.antifreezeMode'>
                <a-radio :value='1'>
                  关闭
                </a-radio>
                <a-radio :value='2'>
                  手动开启
                </a-radio>
                <a-radio :value='3'>
                  根据温度自动启停
                </a-radio>
              </a-radio-group>
            </a-form-item>
            <a-form-item label='自动启停的温度阈值:' name='antifreezeStartRtt'>
              <a-input style="width: 70%" v-model:value='form.antifreezeStartRtt' placeholder='精确到小数点后1位' allow-clear />
            </a-form-item>
            <a-form-item label='防冻模式下的间隔时间(秒):' name='antifreezeInterval'>
              <a-input  style="width: 70%" v-model:value='form.antifreezeInterval' placeholder='单位秒' allow-clear />
            </a-form-item>
            <a-form-item label='防冻模式下每次动作的时长(秒):' name='antifreezeActionTime'>
              <a-input  style="width: 70%" v-model:value='form.antifreezeActionTime' placeholder='单位秒' allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24' :xs='24' />
        </a-row>

        <a-divider>告警设置</a-divider>
        <a-row>
          <a-col :md='12' :sm='24' :xs='24'>
            <a-form-item label='温度报警下限(℃):' name='tempAlarmLow'>
              <a-input v-model:value='form.tempAlarmLow' placeholder='精确到小数点后1位,范围从-500到900' allow-clear />
              <a-alert message="精确到小数点后1位,范围从-500到900" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='温度报警上限(℃):' name='tempAlarmHigh'>
              <a-input v-model:value='form.tempAlarmHigh' placeholder='精确到小数点后1位,范围从-500到900' allow-clear />
              <a-alert message="精确到小数点后1位,范围从-500到900" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='三相电压告警下限:' name='voltageAlarmLow'>
              <a-input-number :min="80" :max="280" v-model:value='form.voltageAlarmLow' placeholder='范围从80到280' allow-clear />
              <a-alert message="范围从80到280,整数" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='三相电压告警上限:' name='voltageAlarmHigh'>
              <a-input-number :min="80" :max="280" v-model:value='form.voltageAlarmHigh' placeholder='范围从80到280' allow-clear />
              <a-alert message="范围从80到280,整数" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
          </a-col>
          <a-col :md='12' :sm='24' :xs='24'>
            <a-form-item label='湿度报警下限(%RH):' name='humAlarmLow'>
              <a-input v-model:value='form.humAlarmLow' placeholder='精确到小数点后1位,范围从0到100' allow-clear />
              <a-alert message="精确到小数点后1位,范围从0到100" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='湿度报警上限(%RH):' name='humAlarmHigh'>
              <a-input v-model:value='form.humAlarmHigh' placeholder='精确到小数点后1位,范围从0到100' allow-clear />
              <a-alert message="精确到小数点后1位,范围从0到100" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='电流告警下限:' name='currentAlarmLow'>
              <a-input v-model:value='form.currentAlarmLow' placeholder='精确到小数点后2位' allow-clear />
              <a-alert message="精确到小数点后2位" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
            <a-form-item label='电流告警上限:' name='currentAlarmHigh'>
              <a-input v-model:value='form.currentAlarmHigh' placeholder='精确到小数点后2位' allow-clear />
              <a-alert message="精确到小数点后2位" style="margin-top:5px;font-size: 11px;padding:2px 3px;" type="info" show-icon />
            </a-form-item>
          </a-col>
        </a-row>
        <a-divider>运行模式设置</a-divider>
        <a-row :gutter='8'>
          <a-col :md='8' :sm='24' :xs='24'>
            <a-form-item label='运行模式' name='runModel'>
              <a-radio-group v-model:value='paramForm.runModel'>
                <a-radio :value='1'>
                  计次模式
                </a-radio>
                <a-radio :value='2'>
                  时间区间模式
                </a-radio>
              </a-radio-group>
            </a-form-item>
          </a-col>
          <a-col :md='14' :sm='24' :xs='24' />
        </a-row>

        <!---------------- 计次模式下的时间段设置----------->
        <a-divider orientation="left"><a-tooltip color='orange' title=''>计次模式下的时间段设置</a-tooltip></a-divider>
        <a-alert message="时间可设置范围是00:00-24:00，清粪总次数的范围是1到253" type="warning" />
        <a-row :gutter="8" style="margin-top : 20px;">
          <a-col :md="6" :sm="24" :xs="24">
            <a-form-item label="计次一的开始时刻:" name="COUNT1_TIME_START">
              <a-time-picker v-model:value="paramForm.COUNT1_TIME_START" format="HH:mm" @change="selectCount1TimeStart"  allow-clear  />
            </a-form-item>
            <a-form-item label="计次二的开始时刻:" name="COUNT2_TIME_START">
              <a-time-picker v-model:value="paramForm.COUNT2_TIME_START" format="HH:mm" @change="selectCount2TimeStart" allow-clear />
            </a-form-item>
            <a-form-item label="计次三的开始时刻:" name="COUNT3_TIME_START">
              <a-time-picker v-model:value="paramForm.COUNT3_TIME_START" format="HH:mm" @change="selectCount3TimeStart" allow-clear />
            </a-form-item>
            <a-form-item label="计次四的开始时刻:" name="COUNT4_TIME_START">
              <a-time-picker v-model:value="paramForm.COUNT4_TIME_START" format="HH:mm" @change="selectCount4TimeStart" allow-clear />
            </a-form-item>
            <a-form-item label="计次五的开始时刻:" name="COUNT5_TIME_START">
              <a-time-picker v-model:value="paramForm.COUNT5_TIME_START" format="HH:mm" @change="selectCount5TimeStart" allow-clear />
            </a-form-item>
            <a-form-item label="计次六的开始时刻:" name="COUNT6_TIME_START">
              <a-time-picker v-model:value="paramForm.COUNT6_TIME_START" format="HH:mm" @change="selectCount6TimeStart" allow-clear />
            </a-form-item>
            <a-form-item label="计次七的开始时刻:" name="COUNT7_TIME_START">
              <a-time-picker v-model:value="paramForm.COUNT7_TIME_START" format="HH:mm" @change="selectCount7TimeStart" allow-clear />
            </a-form-item>
            <a-form-item label="计次八的开始时刻:" name="COUNT8_TIME_START">
              <a-time-picker v-model:value="paramForm.COUNT8_TIME_START" format="HH:mm" @change="selectCount8TimeStart" allow-clear />
            </a-form-item>
            <a-form-item label="计次九的开始时刻:" name="COUNT9_TIME_START">
              <a-time-picker v-model:value="paramForm.COUNT9_TIME_START" format="HH:mm" @change="selectCount9TimeStart" allow-clear />
            </a-form-item>
            <a-form-item label="计次十的开始时刻:" name="COUNT10_TIME_START">
              <a-time-picker v-model:value="paramForm.COUNT10_TIME_START" format="HH:mm" @change="selectCount10TimeStart" allow-clear />
            </a-form-item>
            <a-form-item label="计次十一的开始时刻:" name="COUNT11_TIME_START">
              <a-time-picker v-model:value="paramForm.COUNT11_TIME_START" format="HH:mm" @change="selectCount11TimeStart" allow-clear />
            </a-form-item>
            <a-form-item label="计次十二的开始时刻:" name="COUNT12_TIME_START">
              <a-time-picker v-model:value="paramForm.COUNT12_TIME_START" format="HH:mm" @change="selectCount12TimeStart" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" :xs="24">
            <a-form-item label="清粪总次数:" name="COUNT1_MAX_NUM">
              <a-input-number :min="1" :max="253" v-model:value="calnumModelConfForm.COUNT1_MAX_NUM" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="清粪总次数:" name="COUNT2_MAX_NUM">
              <a-input-number :min="1" :max="253" v-model:value="calnumModelConfForm.COUNT2_MAX_NUM" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="清粪总次数:" name="COUNT3_MAX_NUM">
              <a-input-number :min="1" :max="253" v-model:value="calnumModelConfForm.COUNT3_MAX_NUM" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="清粪总次数:" name="COUNT4_MAX_NUM">
              <a-input-number :min="1" :max="253" v-model:value="calnumModelConfForm.COUNT4_MAX_NUM" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="清粪总次数:" name="COUNT5_MAX_NUM">
              <a-input-number :min="1" :max="253" v-model:value="calnumModelConfForm.COUNT5_MAX_NUM" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="清粪总次数:" name="COUNT6_MAX_NUM">
              <a-input-number :min="1" :max="253" v-model:value="calnumModelConfForm.COUNT6_MAX_NUM" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="清粪总次数:" name="COUNT7_MAX_NUM">
              <a-input-number :min="1" :max="253" v-model:value="calnumModelConfForm.COUNT7_MAX_NUM" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="清粪总次数:" name="COUNT8_MAX_NUM">
              <a-input-number :min="1" :max="253" v-model:value="calnumModelConfForm.COUNT8_MAX_NUM" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="清粪总次数:" name="COUNT9_MAX_NUM">
              <a-input-number :min="1" :max="253" v-model:value="calnumModelConfForm.COUNT9_MAX_NUM" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="清粪总次数:" name="COUNT10_MAX_NUM">
              <a-input-number :min="1" :max="253" v-model:value="calnumModelConfForm.COUNT10_MAX_NUM" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="清粪总次数:" name="COUNT11_MAX_NUM">
              <a-input-number :min="1" :max="253" v-model:value="calnumModelConfForm.COUNT11_MAX_NUM" placeholder="" allow-clear />
            </a-form-item>
            <a-form-item label="清粪总次数:" name="COUNT12_MAX_NUM">
              <a-input-number :min="1" :max="253" v-model:value="calnumModelConfForm.COUNT12_MAX_NUM" placeholder="" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24" :xs="24" >
            <a-form-item label="使能状态:" name="COUNT1_VALID">
              <a-select v-model:value="calnumModelConfForm.COUNT1_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="COUNT2_VALID">
              <a-select v-model:value="calnumModelConfForm.COUNT2_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="COUNT3_VALID">
              <a-select v-model:value="calnumModelConfForm.COUNT3_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="COUNT4_VALID">
              <a-select v-model:value="calnumModelConfForm.COUNT4_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="COUNT5_VALID">
              <a-select v-model:value="calnumModelConfForm.COUNT5_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="COUNT6_VALID">
              <a-select v-model:value="calnumModelConfForm.COUNT6_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="COUNT7_VALID">
              <a-select v-model:value="calnumModelConfForm.COUNT7_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="COUNT8_VALID">
              <a-select v-model:value="calnumModelConfForm.COUNT8_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="COUNT9_VALID">
              <a-select v-model:value="calnumModelConfForm.COUNT9_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="COUNT10_VALID">
              <a-select v-model:value="calnumModelConfForm.COUNT10_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="COUNT11_VALID">
              <a-select v-model:value="calnumModelConfForm.COUNT10_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="COUNT12_VALID">
              <a-select v-model:value="calnumModelConfForm.COUNT12_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24" :xs="24" />
        </a-row>

        <a-divider orientation="left"><a-tooltip color='orange' title=''>时间区间模式下时间段设置</a-tooltip></a-divider>
        <a-alert message="时间可设置范围是00:00-24:00" type="warning" />
        <a-row :gutter="8" style="margin-top : 20px;">
          <a-col :md="6" :sm="24" :xs="24">
            <a-form-item label="时间段一开始时间:" name="TIME1_START">
              <a-time-picker v-model:value="paramForm.TIME1_START" format="HH:mm" @change="selectTime1Start"  allow-clear  />
            </a-form-item>
            <a-form-item label="时间段二开始时间:" name="TIME2_START">
              <a-time-picker v-model:value="paramForm.TIME2_START" format="HH:mm" @change="selectTime2Start" allow-clear />
            </a-form-item>
            <a-form-item label="时间段三开始时间:" name="TIME3_START">
              <a-time-picker v-model:value="paramForm.TIME3_START" format="HH:mm" @change="selectTime3Start" allow-clear />
            </a-form-item>
            <a-form-item label="时间段四开始时间:" name="TIME4_START">
              <a-time-picker v-model:value="paramForm.TIME4_START" format="HH:mm" @change="selectTime4Start" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24" :xs="24">
            <a-form-item label="结束时间(截止24:00):" name="TIME1_STOP">
              <time24-select :value="paramForm.TIME1_OVER" @modify="selectTime1Over" />
            </a-form-item>
            <a-form-item label="结束时间(截止24:00):" name="TIME2_STOP">
              <time24-select :value="paramForm.TIME2_OVER" @modify="selectTime2Over" />
            </a-form-item>
            <a-form-item label="结束时间(截止24:00):" name="TIME3_STOP">
              <time24-select :value="paramForm.TIME3_OVER" @modify="selectTime3Over" />
            </a-form-item>
            <a-form-item label="结束时间(截止24:00):" name="TIME4_STOP">
              <time24-select :value="paramForm.TIME4_OVER" @modify="selectTime4Over" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24" :xs="24" >
            <a-form-item label="使能状态:" name="TIME1_VALID">
              <a-select v-model:value="timeConfForm.TIME1_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="TIME2_VALID">
              <a-select v-model:value="timeConfForm.TIME2_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="TIME3_VALID">
              <a-select v-model:value="timeConfForm.TIME3_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
            <a-form-item label="使能状态:" name="TIME4_VALID">
              <a-select v-model:value="timeConfForm.TIME4_VALID">
                <a-select-option :value="0">不使能</a-select-option>
                <a-select-option :value="1">使能</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24" :xs="24"  />
        </a-row>
      </a-form>
    </a-card>
    <DeviceSlurryscraperFirmwareSprayConfigTemplateSyncsetting v-if="showSelectDevice"
                                                                           v-model:visible="showSelectDevice"
                                                                           :data="current"
                                                                           @done="synctoDevice" />
  </div>
  </a-modal>
</template>

<script>
import dayjs from 'dayjs';
import Time24Select from '@/components/Time24Select/Time24Select.vue';
import { message } from 'ant-design-vue';
import {DeviceSlurryScraperConfigTemplateApi} from "@/api/property/slurryscraper/DeviceSlurryScraperConfigTemplateApi";
import DeviceSlurryscraperFirmwareSprayConfigTemplateSyncsetting from './slurryscraper-firmware-spray-config-template-syncsetting.vue'
import {DeviceSlurryScraperConfigApi} from "@/api/property/slurryscraper/DeviceSlurryScraperConfigApi";
export default {
  name: 'DeviceSlurryscraperFirmwareSprayConfigTemplateEdit',
  components: {
    Time24Select,
    DeviceSlurryscraperFirmwareSprayConfigTemplateSyncsetting
  },
  emits: ['done', 'update:visible'],
  props: {
    // 弹窗是否打开
    visible: Boolean,
    data: Object
  },
  created() {
    if (this.data) {
      this.form = Object.assign({}, this.data);
      this.paramForm.switch = {};
      this.isUpdate = true;
      this.init(this.data);
    } else {
      this.form = {};
      this.paramForm.switch = {};
      this.isUpdate = false;
    }
  },
  data() {
    return {
      form : {},
      paramForm : {},
      timeConfForm : {},
      calnumModelConfForm : {},
      rules: {

      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
      showSelectDevice : false,
      current : null
    };
  },
  methods: {
    updateVisible(value) {
      this.$emit('update:visible', value);
    },
    syncSetting() {
      console.log(this.form);
      this.current = this.form;
      this.showSelectDevice = true;
    },
    synctoDevice (recordId) {
      let that = this;
      DeviceSlurryScraperConfigApi.detail({"recordId" : recordId}).then(res => {
        delete res.recordId;
        delete res.updateTime;
        delete res.updateUser;
        delete res.createTime;
        delete res.createUser;
        res.templateName = that.form.templateName;
        that.init(res);
      }).catch((e) => {
        console.log(e);
      });
    },
    init(initData) {
      let _conf = initData;
      if (_conf) {
        this.form = _conf;
        this.paramForm.switch.masterSwitchCheck = (_conf.masterSwitch == 1) ? true : false;
        this.paramForm.runModel = _conf.runModel;
        let timeConf = Object.assign({}, (_conf.timeModelConf ? (JSON.parse(_conf.timeModelConf) || {}) : {}));
        this.timeConfForm = timeConf;
        if (timeConf) {
          //{"TIME1_START_HOUR":9,"TIME1_START_MIN":30,"TIME1_OVER_HOUR":23,"TIME1_OVER_MIN":59}
          let _TIME1_START_HOUR = timeConf.TIME1_START_HOUR ? Number(timeConf.TIME1_START_HOUR) : 0,
            _TIME1_START_MIN = timeConf.TIME1_START_MIN ? Number(timeConf.TIME1_START_MIN) : 0,
            _TIME1_OVER_HOUR = timeConf.TIME1_OVER_HOUR ? Number(timeConf.TIME1_OVER_HOUR) : 0,
            _TIME1_OVER_MIN = timeConf.TIME1_OVER_MIN ? Number(timeConf.TIME1_OVER_MIN) : 0;
          this.paramForm.TIME1_START= dayjs( ((_TIME1_START_HOUR < 10 ? ("0" + _TIME1_START_HOUR) : _TIME1_START_HOUR) + ":" + (_TIME1_START_MIN < 10 ? ("0" + _TIME1_START_MIN) : _TIME1_START_MIN)), 'HH:mm');
          this.paramForm.TIME1_OVER = [_TIME1_OVER_HOUR, _TIME1_OVER_MIN];
          this.timeConfForm.TIME1_VALID = timeConf.TIME1_VALID ? Number(timeConf.TIME1_VALID) : 0;

          let _TIME2_START_HOUR = timeConf.TIME2_START_HOUR ? Number(timeConf.TIME2_START_HOUR) : 0,
            _TIME2_START_MIN = timeConf.TIME2_START_MIN ? Number(timeConf.TIME2_START_MIN) : 0,
            _TIME2_OVER_HOUR = timeConf.TIME2_OVER_HOUR ? Number(timeConf.TIME2_OVER_HOUR) : 0,
            _TIME2_OVER_MIN = timeConf.TIME2_OVER_MIN ? Number(timeConf.TIME2_OVER_MIN) : 0;
          this.paramForm.TIME2_START = dayjs(((_TIME2_START_HOUR < 10 ? ("0" + _TIME2_START_HOUR) : _TIME2_START_HOUR) + ":" +  (_TIME2_START_MIN < 10 ? ("0" + _TIME2_START_MIN) : _TIME2_START_MIN)), 'HH:mm');
          this.paramForm.TIME2_OVER = [_TIME2_OVER_HOUR, _TIME2_OVER_MIN];
          this.timeConfForm.TIME2_VALID = timeConf.TIME2_VALID ? Number(timeConf.TIME2_VALID) : 0;

          let _TIME3_START_HOUR = timeConf.TIME3_START_HOUR ? Number(timeConf.TIME3_START_HOUR) : 0,
            _TIME3_START_MIN = timeConf.TIME3_START_MIN ? Number(timeConf.TIME3_START_MIN) : 0,
            _TIME3_OVER_HOUR = timeConf.TIME3_OVER_HOUR ? Number(timeConf.TIME3_OVER_HOUR) : 0,
            _TIME3_OVER_MIN= timeConf.TIME3_OVER_MIN ? Number(timeConf.TIME3_OVER_MIN) : 0;
          this.paramForm.TIME3_START = dayjs(((_TIME3_START_HOUR < 10 ? ("0" + _TIME3_START_HOUR) : _TIME3_START_HOUR) + ":" +  (_TIME3_START_MIN < 10 ? ("0" + _TIME3_START_MIN) : _TIME3_START_MIN)), 'HH:mm');
          this.paramForm.TIME3_OVER = [_TIME3_OVER_HOUR, _TIME3_OVER_MIN];
          this.timeConfForm.TIME3_VALID = timeConf.TIME3_VALID ? Number(timeConf.TIME3_VALID) : 0;


          let _TIME4_START_HOUR = timeConf.TIME4_START_HOUR ? Number(timeConf.TIME4_START_HOUR) : 0,
            _TIME4_START_MIN = timeConf.TIME4_START_MIN ? Number(timeConf.TIME4_START_MIN) : 0,
            _TIME4_OVER_HOUR = timeConf.TIME4_OVER_HOUR ? Number(timeConf.TIME4_OVER_HOUR) : 0,
            _TIME4_OVER_MIN = timeConf.TIME4_OVER_MIN ? Number(timeConf.TIME4_OVER_MIN) : 0;
          this.paramForm.TIME4_START = dayjs(((_TIME4_START_HOUR < 10 ? ("0" + _TIME4_START_HOUR) : _TIME4_START_HOUR) + ":" +  (_TIME4_START_MIN < 10 ? ("0" + _TIME4_START_MIN) : _TIME4_START_MIN)), 'HH:mm');
          this.paramForm.TIME4_OVER = [_TIME4_OVER_HOUR,_TIME4_OVER_MIN ];
          this.timeConfForm.TIME4_VALID = timeConf.TIME4_VALID ? Number(timeConf.TIME4_VALID) : 0;
        }

        let calnumModelConf = Object.assign({}, (_conf.calnumModelConf ? (JSON.parse(_conf.calnumModelConf) || {}) : {}));
        this.calnumModelConfForm = calnumModelConf;
        if (calnumModelConf) {
          //{"TIME1_START_HOUR":9,"TIME1_START_MIN":30,"TIME1_OVER_HOUR":23,"TIME1_OVER_MIN":59}
          let _COUNT1_START_HOUR = calnumModelConf.COUNT1_START_HOUR ? Number(calnumModelConf.COUNT1_START_HOUR) : 0,
            _COUNT1_START_MIN = calnumModelConf.COUNT1_START_MIN ? Number(calnumModelConf.COUNT1_START_MIN) : 0;
          this.paramForm.COUNT1_TIME_START= dayjs( ((_COUNT1_START_HOUR < 10 ? ("0" + _COUNT1_START_HOUR) : _COUNT1_START_HOUR) + ":" + (_COUNT1_START_MIN < 10 ? ("0" + _COUNT1_START_MIN) : _COUNT1_START_MIN)), 'HH:mm');

          let _COUNT2_START_HOUR = calnumModelConf.COUNT2_START_HOUR ? Number(calnumModelConf.COUNT2_START_HOUR) : 0,
            _COUNT2_START_MIN = calnumModelConf.COUNT2_START_MIN ? Number(calnumModelConf.COUNT2_START_MIN) : 0;
          this.paramForm.COUNT2_TIME_START= dayjs( ((_COUNT2_START_HOUR < 10 ? ("0" + _COUNT2_START_HOUR) : _COUNT2_START_HOUR) + ":" + (_COUNT2_START_MIN < 10 ? ("0" + _COUNT2_START_MIN) : _COUNT2_START_MIN)), 'HH:mm');

          let _COUNT3_START_HOUR = calnumModelConf.COUNT3_START_HOUR ? Number(calnumModelConf.COUNT3_START_HOUR) : 0,
            _COUNT3_START_MIN = calnumModelConf.COUNT3_START_MIN ? Number(calnumModelConf.COUNT3_START_MIN) : 0;
          this.paramForm.COUNT3_TIME_START= dayjs( ((_COUNT3_START_HOUR < 10 ? ("0" + _COUNT3_START_HOUR) : _COUNT3_START_HOUR) + ":" + (_COUNT3_START_MIN < 10 ? ("0" + _COUNT3_START_MIN) : _COUNT3_START_MIN)), 'HH:mm');

          let _COUNT4_START_HOUR = calnumModelConf.COUNT4_START_HOUR ? Number(calnumModelConf.COUNT4_START_HOUR) : 0,
            _COUNT4_START_MIN = calnumModelConf.COUNT4_START_MIN ? Number(calnumModelConf.COUNT4_START_MIN) : 0;
          this.paramForm.COUNT4_TIME_START= dayjs( ((_COUNT4_START_HOUR < 10 ? ("0" + _COUNT4_START_HOUR) : _COUNT4_START_HOUR) + ":" + (_COUNT4_START_MIN < 10 ? ("0" + _COUNT4_START_MIN) : _COUNT4_START_MIN)), 'HH:mm');

          let _COUNT5_START_HOUR = calnumModelConf.COUNT5_START_HOUR ? Number(calnumModelConf.COUNT5_START_HOUR) : 0,
            _COUNT5_START_MIN = calnumModelConf.COUNT5_START_MIN ? Number(calnumModelConf.COUNT5_START_MIN) : 0;
          this.paramForm.COUNT5_TIME_START= dayjs( ((_COUNT5_START_HOUR < 10 ? ("0" + _COUNT5_START_HOUR) : _COUNT5_START_HOUR) + ":" + (_COUNT5_START_MIN < 10 ? ("0" + _COUNT5_START_MIN) : _COUNT5_START_MIN)), 'HH:mm');

          let _COUNT6_START_HOUR = calnumModelConf.COUNT6_START_HOUR ? Number(calnumModelConf.COUNT6_START_HOUR) : 0,
            _COUNT6_START_MIN = calnumModelConf.COUNT6_START_MIN ? Number(calnumModelConf.COUNT6_START_MIN) : 0;
          this.paramForm.COUNT6_TIME_START= dayjs( ((_COUNT6_START_HOUR < 10 ? ("0" + _COUNT6_START_HOUR) : _COUNT6_START_HOUR) + ":" + (_COUNT6_START_MIN < 10 ? ("0" + _COUNT6_START_MIN) : _COUNT6_START_MIN)), 'HH:mm');

          let _COUNT7_START_HOUR = calnumModelConf.COUNT7_START_HOUR ? Number(calnumModelConf.COUNT7_START_HOUR) : 0,
            _COUNT7_START_MIN = calnumModelConf.COUNT7_START_MIN ? Number(calnumModelConf.COUNT7_START_MIN) : 0;
          this.paramForm.COUNT7_TIME_START= dayjs( ((_COUNT7_START_HOUR < 10 ? ("0" + _COUNT7_START_HOUR) : _COUNT7_START_HOUR) + ":" + (_COUNT7_START_MIN < 10 ? ("0" + _COUNT7_START_MIN) : _COUNT7_START_MIN)), 'HH:mm');

          let _COUNT8_START_HOUR = calnumModelConf.COUNT8_START_HOUR ? Number(calnumModelConf.COUNT8_START_HOUR) : 0,
            _COUNT8_START_MIN = calnumModelConf.COUNT8_START_MIN ? Number(calnumModelConf.COUNT8_START_MIN) : 0;
          this.paramForm.COUNT8_TIME_START= dayjs( ((_COUNT8_START_HOUR < 10 ? ("0" + _COUNT8_START_HOUR) : _COUNT8_START_HOUR) + ":" + (_COUNT8_START_MIN < 10 ? ("0" + _COUNT8_START_MIN) : _COUNT8_START_MIN)), 'HH:mm');

          let _COUNT9_START_HOUR = calnumModelConf.COUNT9_START_HOUR ? Number(calnumModelConf.COUNT9_START_HOUR) : 0,
            _COUNT9_START_MIN = calnumModelConf.COUNT9_START_MIN ? Number(calnumModelConf.COUNT9_START_MIN) : 0;
          this.paramForm.COUNT9_TIME_START= dayjs( ((_COUNT9_START_HOUR < 10 ? ("0" + _COUNT9_START_HOUR) : _COUNT9_START_HOUR) + ":" + (_COUNT9_START_MIN < 10 ? ("0" + _COUNT9_START_MIN) : _COUNT9_START_MIN)), 'HH:mm');

          let _COUNT10_START_HOUR = calnumModelConf.COUNT10_START_HOUR ? Number(calnumModelConf.COUNT10_START_HOUR) : 0,
            _COUNT10_START_MIN = calnumModelConf.COUNT10_START_MIN ? Number(calnumModelConf.COUNT10_START_MIN) : 0;
          this.paramForm.COUNT10_TIME_START= dayjs( ((_COUNT10_START_HOUR < 10 ? ("0" + _COUNT10_START_HOUR) : _COUNT10_START_HOUR) + ":" + (_COUNT10_START_MIN < 10 ? ("0" + _COUNT10_START_MIN) : _COUNT10_START_MIN)), 'HH:mm');

          let _COUNT11_START_HOUR = calnumModelConf.COUNT11_START_HOUR ? Number(calnumModelConf.COUNT11_START_HOUR) : 0,
            _COUNT11_START_MIN = calnumModelConf.COUNT11_START_MIN ? Number(calnumModelConf.COUNT11_START_MIN) : 0;
          this.paramForm.COUNT11_TIME_START= dayjs( ((_COUNT11_START_HOUR < 10 ? ("0" + _COUNT11_START_HOUR) : _COUNT11_START_HOUR) + ":" + (_COUNT11_START_MIN < 10 ? ("0" + _COUNT11_START_MIN) : _COUNT11_START_MIN)), 'HH:mm');

          let _COUNT12_START_HOUR = calnumModelConf.COUNT12_START_HOUR ? Number(calnumModelConf.COUNT12_START_HOUR) : 0,
            _COUNT12_START_MIN = calnumModelConf.COUNT12_START_MIN ? Number(calnumModelConf.COUNT12_START_MIN) : 0;
          this.paramForm.COUNT12_TIME_START= dayjs( ((_COUNT12_START_HOUR < 10 ? ("0" + _COUNT12_START_HOUR) : _COUNT12_START_HOUR) + ":" + (_COUNT12_START_MIN < 10 ? ("0" + _COUNT12_START_MIN) : _COUNT12_START_MIN)), 'HH:mm');


          //转成数字
          this.calnumModelConfForm.COUNT1_MAX_NUM = calnumModelConf.COUNT1_MAX_NUM ? Number(calnumModelConf.COUNT1_MAX_NUM) : 0;
          this.calnumModelConfForm.COUNT2_MAX_NUM = calnumModelConf.COUNT2_MAX_NUM ? Number(calnumModelConf.COUNT2_MAX_NUM) : 0;
          this.calnumModelConfForm.COUNT3_MAX_NUM = calnumModelConf.COUNT3_MAX_NUM ? Number(calnumModelConf.COUNT3_MAX_NUM) : 0;
          this.calnumModelConfForm.COUNT4_MAX_NUM = calnumModelConf.COUNT4_MAX_NUM ? Number(calnumModelConf.COUNT4_MAX_NUM) : 0;
          this.calnumModelConfForm.COUNT5_MAX_NUM = calnumModelConf.COUNT5_MAX_NUM ? Number(calnumModelConf.COUNT5_MAX_NUM) : 0;
          this.calnumModelConfForm.COUNT6_MAX_NUM = calnumModelConf.COUNT6_MAX_NUM ? Number(calnumModelConf.COUNT6_MAX_NUM) : 0;
          this.calnumModelConfForm.COUNT7_MAX_NUM = calnumModelConf.COUNT7_MAX_NUM ? Number(calnumModelConf.COUNT7_MAX_NUM) : 0;
          this.calnumModelConfForm.COUNT8_MAX_NUM = calnumModelConf.COUNT8_MAX_NUM ? Number(calnumModelConf.COUNT8_MAX_NUM) : 0;
          this.calnumModelConfForm.COUNT9_MAX_NUM = calnumModelConf.COUNT9_MAX_NUM ? Number(calnumModelConf.COUNT9_MAX_NUM) : 0;
          this.calnumModelConfForm.COUNT10_MAX_NUM = calnumModelConf.COUNT10_MAX_NUM ? Number(calnumModelConf.COUNT10_MAX_NUM) : 0;
          this.calnumModelConfForm.COUNT11_MAX_NUM = calnumModelConf.COUNT11_MAX_NUM ? Number(calnumModelConf.COUNT11_MAX_NUM) : 0;
          this.calnumModelConfForm.COUNT12_MAX_NUM = calnumModelConf.COUNT12_MAX_NUM ? Number(calnumModelConf.COUNT12_MAX_NUM) : 0;

          //使能状态
          this.calnumModelConfForm.COUNT1_VALID = calnumModelConf.COUNT1_VALID ? Number(calnumModelConf.COUNT1_VALID) : 0;
          this.calnumModelConfForm.COUNT2_VALID = calnumModelConf.COUNT2_VALID ? Number(calnumModelConf.COUNT2_VALID) : 0;
          this.calnumModelConfForm.COUNT3_VALID = calnumModelConf.COUNT3_VALID ? Number(calnumModelConf.COUNT3_VALID) : 0;
          this.calnumModelConfForm.COUNT4_VALID = calnumModelConf.COUNT4_VALID ? Number(calnumModelConf.COUNT4_VALID) : 0;
          this.calnumModelConfForm.COUNT5_VALID = calnumModelConf.COUNT5_VALID ? Number(calnumModelConf.COUNT5_VALID) : 0;
          this.calnumModelConfForm.COUNT6_VALID = calnumModelConf.COUNT6_VALID ? Number(calnumModelConf.COUNT6_VALID) : 0;
          this.calnumModelConfForm.COUNT7_VALID = calnumModelConf.COUNT7_VALID ? Number(calnumModelConf.COUNT7_VALID) : 0;
          this.calnumModelConfForm.COUNT8_VALID = calnumModelConf.COUNT8_VALID ? Number(calnumModelConf.COUNT8_VALID) : 0;
          this.calnumModelConfForm.COUNT9_VALID = calnumModelConf.COUNT9_VALID ? Number(calnumModelConf.COUNT9_VALID) : 0;
          this.calnumModelConfForm.COUNT10_VALID = calnumModelConf.COUNT10_VALID ? Number(calnumModelConf.COUNT10_VALID) : 0;
          this.calnumModelConfForm.COUNT11_VALID = calnumModelConf.COUNT11_VALID ? Number(calnumModelConf.COUNT11_VALID) : 0;
          this.calnumModelConfForm.COUNT12_VALID = calnumModelConf.COUNT12_VALID ? Number(calnumModelConf.COUNT12_VALID) : 0;
        }
      }
    },

    masterSwitchChange(checked) {
      console.log(checked);
      this.paramForm.switch.masterSwitchCheck = checked;
    },

    selectCount1TimeStart(time) {
      this.calnumModelConfForm.COUNT1_START_HOUR = time.hour();
      this.calnumModelConfForm.COUNT1_START_MIN = time.minute();
    },
    selectCount2TimeStart(time) {
      this.calnumModelConfForm.COUNT2_START_HOUR = time.hour();
      this.calnumModelConfForm.COUNT2_START_MIN = time.minute();
    },
    selectCount3TimeStart(time) {
      this.calnumModelConfForm.COUNT3_START_HOUR = time.hour();
      this.calnumModelConfForm.COUNT3_START_MIN = time.minute();
    },
    selectCount4TimeStart(time) {
      this.calnumModelConfForm.COUNT4_START_HOUR = time.hour();
      this.calnumModelConfForm.COUNT4_START_MIN = time.minute();
    },
    selectCount5TimeStart(time) {
      this.calnumModelConfForm.COUNT5_START_HOUR = time.hour();
      this.calnumModelConfForm.COUNT5_START_MIN = time.minute();
    },
    selectCount6TimeStart(time) {
      this.calnumModelConfForm.COUNT6_START_HOUR = time.hour();
      this.calnumModelConfForm.COUNT6_START_MIN = time.minute();
    },
    selectCount7TimeStart(time) {
      this.calnumModelConfForm.COUNT7_START_HOUR = time.hour();
      this.calnumModelConfForm.COUNT7_START_MIN = time.minute();
    },
    selectCount8TimeStart(time) {
      this.calnumModelConfForm.COUNT8_START_HOUR = time.hour();
      this.calnumModelConfForm.COUNT8_START_MIN = time.minute();
    },
    selectCount9TimeStart(time) {
      this.calnumModelConfForm.COUNT9_START_HOUR = time.hour();
      this.calnumModelConfForm.COUNT9_START_MIN = time.minute();
    },
    selectCount10TimeStart(time) {
      this.calnumModelConfForm.COUNT10_START_HOUR = time.hour();
      this.calnumModelConfForm.COUNT10_START_MIN = time.minute();
    },
    selectCount11TimeStart(time) {
      this.calnumModelConfForm.COUNT11_START_HOUR = time.hour();
      this.calnumModelConfForm.COUNT11_START_MIN = time.minute();
    },
    selectCount12TimeStart(time) {
      this.calnumModelConfForm.COUNT12_START_HOUR = time.hour();
      this.calnumModelConfForm.COUNT12_START_MIN = time.minute();
    },

    selectTime1Start(time) {
      this.timeConfForm.TIME1_START_HOUR = time.hour();
      this.timeConfForm.TIME1_START_MIN = time.minute();
    },
    selectTime2Start(time) {
      this.timeConfForm.TIME2_START_HOUR = time.hour();
      this.timeConfForm.TIME2_START_MIN = time.minute();
    },
    selectTime3Start(time) {
      this.timeConfForm.TIME3_START_HOUR = time.hour();
      this.timeConfForm.TIME3_START_MIN = time.minute();
    },
    selectTime4Start(time) {
      this.timeConfForm.TIME4_START_HOUR = time.hour();
      this.timeConfForm.TIME4_START_MIN = time.minute();
    },

    selectTime1Over(time) {
      this.paramForm.TIME1_OVER = time;
      if (time) {
        this.timeConfForm.TIME1_OVER_HOUR = time[0];
        this.timeConfForm.TIME1_OVER_MIN = time[1];
      }
    },
    selectTime2Over(time) {
      this.paramForm.TIME2_OVER = time;
      if (time) {
        this.timeConfForm.TIME2_OVER_HOUR = time[0];
        this.timeConfForm.TIME2_OVER_MIN = time[1];
      }
    },
    selectTime3Over(time) {
      this.paramForm.TIME3_OVER = time;
      if (time) {
        this.timeConfForm.TIME3_OVER_HOUR = time[0];
        this.timeConfForm.TIME3_OVER_MIN = time[1];
      }
    },
    selectTime4Over(time) {
      this.paramForm.TIME4_OVER = time;
      if (time) {
        this.timeConfForm.TIME4_OVER_HOUR = time[0];
        this.timeConfForm.TIME4_OVER_MIN = time[1];
      }
    },


    /**
     * 保存和编辑
     * 写到队列，队列发送完回写到原配置
     * @author cancan
     * @date 2022/03/04 21:15
     */
    save() {
      //将"结束时间"00：00转为24点吧。this.timeConfForm.TIME6_OVER_HOUR结束
      let timeModelConf = this.timeConfForm;
      let calnumModelConf = this.calnumModelConfForm;
      if ((this.timeConfForm.TIME1_START_HOUR * 100 + this.timeConfForm.TIME1_START_MIN) > (this.timeConfForm.TIME1_OVER_HOUR * 100 + this.timeConfForm.TIME1_OVER_MIN)) {
        message.error('时间段一开始时间应小于结束时间，请重新输入');
        return;
      }
      if ((this.timeConfForm.TIME2_START_HOUR * 100 + this.timeConfForm.TIME2_START_MIN) > (this.timeConfForm.TIME2_OVER_HOUR * 100 + this.timeConfForm.TIME2_OVER_MIN)) {
        message.error('时间段二开始时间应小于结束时间，请重新输入');
        return;
      }
      if ((this.timeConfForm.TIME3_START_HOUR * 100 + this.timeConfForm.TIME3_START_MIN) > (this.timeConfForm.TIME3_OVER_HOUR * 100 + this.timeConfForm.TIME3_OVER_MIN)) {
        message.error('时间段三开始时间应小于结束时间，请重新输入');
        return;
      }
      if ((this.timeConfForm.TIME4_START_HOUR * 100 + this.timeConfForm.TIME4_START_MIN) > (this.timeConfForm.TIME4_OVER_HOUR * 100 + this.timeConfForm.TIME4_OVER_MIN)) {
        message.error('时间段四开始时间应小于结束时间，请重新输入');
        return;
      }

      this.form.masterSwitch = this.paramForm.switch.masterSwitchCheck ? 1 : 2;
      this.form.calnumModelConf = JSON.stringify(calnumModelConf);
      this.form.timeModelConf = JSON.stringify(timeModelConf);
      this.form.runModel = this.paramForm.runModel;

      // 修改加载框为正在加载
      this.loading = true;
      let result = null;
      // 执行编辑或修改
      if (this.isUpdate) {
        result = DeviceSlurryScraperConfigTemplateApi.edit(this.form);
      } else {
        result = DeviceSlurryScraperConfigTemplateApi.add(this.form);
      }
      result.then(res => {
          // 移除加载框
          this.loading = false;
          // 提示添加成功
          message.success(res.message);
          // 如果是新增，则form表单置空
          if (!this.isUpdate) {
            this.form = {};
          }
          // 关闭弹框，通过控制visible的值，传递给父组件
          this.updateVisible(false);
          // 触发父组件done事件
          this.$emit('done');
        })
        .catch(() => {
          this.loading = false;
        });
    }
  }
};
</script>
<style scoped>
/** 用户卡片 */
.workplace-user-card .ele-cell-content {
  overflow: hidden;
}

.workplace-user-card h4 {
  margin-bottom: 6px;
}
.regionclass /deep/ .ant-col-md-11 {
  max-width : 30% !important;
}
.regionclass /deep/ .ant-col-md-13 {
  max-width: 70% !important;
}
</style>
